#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2014年12月16日

@author: chenyongbing
'''
import sys,os
current_dir = os.path.dirname(__file__)
sys.path.append(os.path.join(current_dir,'../../'))
from base.PyMySQL import ConnectMySQL

from base.localConfig import baseLocalConfig


zhimofi_host = baseLocalConfig.mysqlConfig['zhimofi']['host']
zhimofi_user = baseLocalConfig.mysqlConfig['zhimofi']['user']
zhimofi_passwd = baseLocalConfig.mysqlConfig['zhimofi']['passwd']
zhimofi_db = baseLocalConfig.mysqlConfig['zhimofi']['db']
print zhimofi_passwd
myZhiMofi = ConnectMySQL(zhimofi_host,zhimofi_user,zhimofi_passwd,zhimofi_db)
import logging


class ApAuthUserStats(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
    def get_ap_auth_user_flow(self,tab='device_user_detail',day=None,hour=None,device=None,auth_type=1):
        
        
        query = 'select sum(upflow+downflow) from %s'%tab
        if day!=None:
            query  = query + ' where  date(start_time)="%s"'%day
        else:
            pass
        if device!=None:
            query = query + ' and deviceid="%s" '%device
        if hour!=None:
            query = query + ' and hour(start_time)="%s"'%hour
        logging.debug( query)
        ret = myZhiMofi.SelectOne(query)
        if ret:
            return ret[0]
        else:return None
        
if __name__ == '__main__':
    myApAuthUserStats = ApAuthUserStats()
    print myApAuthUserStats.get_ap_auth_user_flow( day="2014-12-11", hour="13")